package com.yx.cloud.product.laser.inxni.convert;

import com.iot.product.sweeper.bean.Robot;
import com.iot.common.utils.Event;
import com.yx.cloud.product.laser.inxni.INXNIConstant;
import com.iot.common.utils.LogUtils;

import org.json.JSONException;
import org.json.JSONObject;

public class INXNIDataConverter {
    private final static String TAG = "INXNIDataConverter";

    public static void parseDp(Robot robot,String dps) {
        LogUtils.i("aaaaaaaaaa INXNI DPParser dps: " + dps);
        try {
            JSONObject jsonObject = new JSONObject(dps);
            if (jsonObject.has(INXNIConstant.AUTO_BOOST)) {
                //地毯增压
                boolean auto_boost = jsonObject.getBoolean(INXNIConstant.AUTO_BOOST);
                robot.getCleanSettings().setCarpetPressurize(auto_boost);
                Event.newBuilder().type(Event.MSG_ROBOT_SETTINGS).result(true).send();
            }
            if (jsonObject.has(INXNIConstant.CUSTOM_MODE_SWITCH)) {
                //定制模式开关
                boolean customMode = jsonObject.getBoolean(INXNIConstant.CUSTOM_MODE_SWITCH);
                robot.getCleanSettings().setCustomSwitch(customMode);
                Event.newBuilder().type(Event.MSG_ROBOT_SETTINGS).result(true).send();
            }
            if (jsonObject.has(INXNIConstant.DUST_BOX)) {
                //尘盒状态  true:已安装 false:未安装
                boolean dustBoxStatus = jsonObject.getBoolean(INXNIConstant.DUST_BOX);
                robot.getCleanSettings().setDustBoxStatus(dustBoxStatus);
                Event.newBuilder().type(Event.MESSAGE_TYPE_TANK_DUSTBOX_STATUS).send();
            }
            if (jsonObject.has(INXNIConstant.WATER_TANK)) {
                //水箱状态  true:已安装 false:未安装
                boolean tankStatus = jsonObject.getBoolean(INXNIConstant.WATER_TANK);
                robot.getCleanSettings().setTankStatus(tankStatus);
                Event.newBuilder().type(Event.MESSAGE_TYPE_TANK_DUSTBOX_STATUS).send();
            }
            if (jsonObject.has(INXNIConstant.MSG_PUSH_UNSEEN)) {
                //消息推送
                int news_push = jsonObject.getInt(INXNIConstant.MSG_PUSH_UNSEEN);
            }
            if (jsonObject.has(INXNIConstant.WATER_TANK_FILTER)) {
                //扫拖模块滤网/水箱滤网(X3 X3S)
                int water_tank_filter = jsonObject.getInt(INXNIConstant.WATER_TANK_FILTER) * 60;
                robot.getConsumption().setWaterTankFilterLife(water_tank_filter);
                Event.newBuilder().result(true).type(Event.MESSAGE_TYPE_GET_CONSUMPTION).content("X3").send();
            }
            if (jsonObject.has(INXNIConstant.LIGHT_SWITCH)) {
                //灯光（青春版）
                boolean lightSwitch = jsonObject.getBoolean(INXNIConstant.LIGHT_SWITCH);
                robot.getCleanSettings().setLightSwitch(lightSwitch);
            }
            if (jsonObject.has(INXNIConstant.TMALL_DEVICE_ID)) {
                //天猫精灵设备ID
                String tamllDeviceId = jsonObject.getString(INXNIConstant.TMALL_DEVICE_ID);
                INXNIConstant.DEVICE_ID = tamllDeviceId;
                robot.getCleanSettings().setTmallDeviceId(tamllDeviceId);
                LogUtils.i("aaaaaaaaaa INXNI DPParser dps: 天猫精灵设备ID : " + tamllDeviceId);
            }
            if(jsonObject.has(INXNIConstant.OPEN_MULTI_MAP)){
                //多楼层地图
                boolean openMultiMap = jsonObject.getBoolean(INXNIConstant.OPEN_MULTI_MAP);
                robot.getCleanSettings().setOpenMultiMap(openMultiMap);
                Event.newBuilder().type(Event.MSG_ROBOT_MULTI_MAP).result(true).send();
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
